
Tracks = function() {
	this.list = {};
	this.active = {};
};

Tracks.prototype.reset = function() {
	this.list = {};
};

Tracks.prototype.select = function(id) {
	this.active = this.list[id] || {};
};

Tracks.prototype.add= function(id, track) {
	this.list[id] = track;
}

Tracks.prototype.update = function(arr, callback) {
	if(Array.isArray(arr)) {
		this.reset();
		for(var i = 0; i < arr.length; i++) {
			this.list[arr[i].id] = arr[i];
		}
	}
	callback();
};

Error = function() {
	this.message = "";
	this.code = 0;
};

Error.prototype.set = function(obj) {
	this.message = obj.message || "";
	this.code = obj.code || 0;
};

Error.prototype.clear = function() {
	this.message = "";
	this.code = 0;
};

Session = function() {
	this.login = false;
	this.id = 0;
	this.user = {};
};

Session.prototype.set = function(obj) {
	this.id = obj.id || 0;
	this.user = obj.user || {};
	
	if(this.id != 0) {
		this.login = true;
	}
};

Session.prototype.setCookie = function() {
	cookieDate = new Date();
	cookieDate.setHours(cookieDate.getHours() + 1); // 1 hour session
	document.cookie = "trackerSession=" + this.id + ";expires=" + cookieDate.toUTCString();
};

Session.prototype.getCookie = function() {
	var cookie = document.cookie.match(/trackerSession=(\d+)/i) || [];
	if(cookie.length >=2) {
		this.id = cookie[1];
		return true;
	} else {
		return false;
	}
};

Session.prototype.destroy = function() {
	this.login = false;
	this.id = 0;
	this.user = {};
	document.cookie = "trackerSession=";
};

Session.prototype.command = function(cmd, o) {
	o = o || {};
	
	o.command = cmd;
	o.session = this;
	return o;
	
};
